package com.handinfo.game;

import java.util.Calendar;
import java.util.TimeZone;

public class MailItem
{
	public static final byte TYPE_MAIL_SYS = 0;
	public static final byte TYPE_MAIL_COL = 1;
	public static final byte TYPE_MAIL_NOR = 2;
	//
	public static final byte STATE_MAIL_NEW = 0;//新邮件
	public static final byte STATE_MAIL_UNREAD = 1;//未读取右邮件
	public static final byte STATE_MAIL_READ = 2;//已读邮件
	public static final byte STATE_MAIL_PICKED = 3;//提取附件
	//
	public static short s_num_newMail;//新邮件数目
	//data logic
	public long m_id;
	public String m_title;
	public String m_date;
	public byte m_state;//状态码
	public byte m_type; //邮件类型
	//data dis
	public boolean m_isSel;//是否被选中

	/**
	 * 格林威治时间转换为标准时间
	 * @param time
	 * @return
	 */
	public static final String getTime(long time)
	{
		TimeZone tz = TimeZone.getDefault();
		Calendar ca = Calendar.getInstance(tz);

		//Calendar 的 getInstance 方法返回一个 Calendar 对象，其日历字段已由当前日期和时间初始化 
		String strYear = String.valueOf(ca.get(Calendar.YEAR)); //获取当前年时间并转为字符串型 
		strYear = strYear.substring(2, strYear.length());
		String strMonth = String.valueOf(ca.get(Calendar.MONTH) + 1); //获取当前月时间并转为字符串型 

		//ca.get(Calendar.MONTH)+1为什么加一是因为,0表示1月,1表示2月,依次类推 
		String strDate = String.valueOf(ca.get(Calendar.DATE)); //获取当前日时间并转为字符串型 
		String SysDate = null;
		if ((ca.get(Calendar.MONTH) + 1) <= 9 && ca.get(Calendar.DATE) <= 9) {
			SysDate = strYear + "0" + strMonth + "0" + strDate;
		}
		else if ((ca.get(Calendar.MONTH) + 1) > 9 && ca.get(Calendar.DATE) > 9) {
			SysDate = strYear + strMonth + strDate;
		}
		else if ((ca.get(Calendar.MONTH) + 1) <= 9 && ca.get(Calendar.DATE) > 9) {
			SysDate = strYear + "0" + strMonth + strDate;
		}
		else if ((ca.get(Calendar.MONTH) + 1) > 9 && ca.get(Calendar.DATE) <= 9) {
			SysDate = strYear + strMonth + "0" + strDate;
		}
		else {
			SysDate = "NONE";
		}
		return SysDate;
	}

	public static final MailItem[] getTestMailItems(int num)
	{
		return getTestMailItems(num, MailItem.TYPE_MAIL_NOR, 20, "Test", 200,"sender", "recver");
	}

	public static final MailItem[] getTestMailItems(int num, byte type, int id,
			String title, int date, String sender, String recver)
	{
		MailItem[] items = new MailItem[num];
		for (int i = 0; i < items.length; i++) {
			items[i] = getTestMailItem(type, id + i, title + " " + i,
					(date + i) + "", sender + i, recver + i);
		}
		return items;
	}

	public static final MailItem getTestMailItem(byte type, int id, String title, String date, String sender, String recver)
	{
		MailItem item = new MailItem();
		item.m_id = id;
		item.m_title = title;
		item.m_date = date;
		return item;
	}

}
